#include "StdAfx.h"
#include "LitScriptPrereqs.h"
#include "LitScriptEngine.h"

namespace Lit
{
	ScriptRuntimeError::ScriptRuntimeError( const std::string& script_function,  size_t script_line, const std::string& script_msg, const std::string &source_func,  size_t source_line, const std::string &source_file )
		: RuntimeError( "[ScriptRuntimeError|"+script_function+":"+String(script_line).str()+"]: "+script_msg, source_func, source_line, source_file )
		, mFunction( script_function ), mLine(script_line), mDesc(script_msg){}
	ScriptRuntimeError::~ScriptRuntimeError(){}

	size_t ScriptRuntimeError::scriptLine() const{ return mLine; }
	const std::string& ScriptRuntimeError::scriptMessage() const{ return mDesc; }
	const std::string& ScriptRuntimeError::scriptFunction() const{ return mFunction; }

	ScriptEngineError::ScriptEngineError( const std::string &message, const std::string &source_func,  size_t source_line, const std::string &source_file ) : LogicError( "[ScriptEngine: "+message, source_func, source_line, source_file ){}
	ScriptEngineError::~ScriptEngineError()	{}

	ScriptDeclarationError::ScriptDeclarationError( const std::string &decl, int ret_code, const std::string &func, const size_t line, const std::string &file ) : ScriptEngineError( String("Cannot register '")(decl)("', engine returned ")(ret_code)(" (")(ScriptEngine::trReturnCode(ret_code))(")").str(), func, line, file ){}

	ScriptNoEntryPoint::ScriptNoEntryPoint( const std::string &entry_point, const std::string &source_func,  size_t source_line, const std::string &source_file ) : ScriptEngineError( "Missing entry_point '"+entry_point+"'", source_func, source_line, source_file ){}
	ScriptNoEntryPoint::~ScriptNoEntryPoint(){}

	ScriptInvalidContext::ScriptInvalidContext( const std::string &source_func,  size_t source_line, const std::string &source_file ) : ScriptEngineError( "Invalid Context ", source_func, source_line, source_file ){}
	ScriptInvalidContext::~ScriptInvalidContext(){}
	
	PreprocessorError::PreprocessorError( ScriptPreprocessorPtr proc, const std::string &unit_name, ErrorCode c, const std::string &error, size_t line ): m_proc(proc), m_nam(unit_name), m_lin(line), m_err(error), p_code(c), std::runtime_error( ("["+unit_name+"|"+Ogre::StringConverter::toString(line)+"]:"+error+" code("+Ogre::StringConverter::toString(c)+")").c_str() ){}
	PreprocessorError::PreprocessorError( const PreprocessorError& rk ): m_proc(rk.m_proc), p_code(rk.p_code), m_err(rk.m_err), m_lin(rk.m_lin), m_nam(rk.m_nam), std::runtime_error(rk.what()){}
	PreprocessorError::~PreprocessorError( ){}

	const char * PreprocessorError::what() const{ static std::string str = ("["+m_nam+"|"+Ogre::StringConverter::toString(m_lin)+"]:"+m_err+" code("+Ogre::StringConverter::toString(p_code)+")"); return str.c_str(); }
		
	ScriptPreprocessorPtr PreprocessorError::getPreprocessor(){ return m_proc; }
	const ScriptPreprocessorPtr PreprocessorError::getPreprocessor() const{ return m_proc; }

	std::string PreprocessorError::getError() const{ return m_err; }
	std::string PreprocessorError::getUnitName() const{ return m_nam; }
	size_t PreprocessorError::getLine() const {return m_lin; }
	PreprocessorError::ErrorCode PreprocessorError::getCode() const{ return p_code; }
	/*/////////////////////////////////////
				SCRIPT
	/////////////////////////////////////*/
};